from soj.builtin.compare.fulltext.fulltext import FullTextCompare
from soj.builtin.compare.float.float import FloatCompare,DEFAULT_PRECISION
from soj.builtin.compare.syscmd.syscmd import SyscmdCompare
from soj.builtin.compare.token.token import TokenCompare
# spj compare has not implemented yet
from soj.builtin.compare.common import CompareType


def get_compare_engine_by_dict(conf:dict,file_p,file_j):
    '''
    The conf dict should be in format like:
    {
        "type":"fulltext"|"syscmd"|"token"|"float",
        // Other fields specific to each compare type
    }
    if type is "float", additional fields are required:
        "precision":int
    '''
    ctype=CompareType(conf.get("type","fulltext"))
    if ctype==CompareType.FULLTEXT:
        return FullTextCompare(file_p,file_j)
    elif ctype==CompareType.SYSCMD:
        return SyscmdCompare(file_p,file_j)
    elif ctype==CompareType.TOKEN:
        return TokenCompare(file_p,file_j)
    elif ctype==CompareType.FLOAT:
        precision=conf.get("precision",DEFAULT_PRECISION)
        return FloatCompare(file_p,file_j,precision)
    else:
        raise NotImplementedError(f"Compare type {ctype} is not implemented.")